package com.example.mapstruct_demo.controller;

import com.example.mapstruct_demo.controller.mapper.UserMapper;
import com.example.mapstruct_demo.pojo.dto.UserDto;
import com.example.mapstruct_demo.pojo.vo.UserVo;
import com.example.mapstruct_demo.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 77229
 */
@RestController
public class TestController {

    @Autowired
    private TestService testService;

    @PostMapping(value = "test/save")
    public Object save(@RequestBody UserVo vo) {
        UserDto userDto = UserMapper.INSTANCE.vo2dto(vo);
        testService.save(userDto);
        return "success";
    }

    @GetMapping(value = "test/find/{userId}")
    public Object find(@PathVariable Long userId) {
        UserDto userDto = testService.find(userId);
        return UserMapper.INSTANCE.dto2vo(userDto);
    }
}
